Dear Heavenly Father,
We start this day asking for your joy and strength in this moment when we are practicing these programming skills.
Please let this be a moment of true fellowship and character building in our community of learning.
Be with us in any difficulties we face. Give us a disposition to help, and humility to be helped.
Give us wisdom to discern your beauty and justice as we write these Python programs.
May everything we do and learn here be offered to you in praise, gratitude and service to our neighbors.
In Jesus name we pray. Amen.
A variable is a function that defines an object.
A variable points to the memory location of an object.
A variable is a unique identifier within a class, while an object is a function.
A variable can only store primitive data types, whereas an object stores complex data types.
Given the following Python code snippet:
Identify the data types of the variables x, y, z, and w.
Review the following Python code snippet:
What is the problem with the variable name def in this code, and how can it be corrected?
Review the following lines of code, each involving the assignment operator (=). Determine whether the assignment is correct or incorrect for each line. Justify your answer, and if a line contains an error, provide the correct version of the code.
length * width = area
num = 3.14
x, y, z = 1, 2, 3
10 = ten_value
score by 5?score = score + 5
score = score - 5
score += 5
score =+ 5
What is the problem with this code when attempting to swap the values of a and b, and what will be the final values of a and b?
The command-line interface will ask for input from our keyboard, and then:
print()print("Hello World")\n: print("Hello\nWorld")print("x has the value:", x, "\nand y has the value:", y)input()input() “turns” into the text entered, and is ALWAYS an object the type string!x = input()
x = "Hi"What happened???
int() and float()
Like in any language, style and form makes a BIG difference. One could say that it doesn’t matter once it works, however, that is a very narrow way to understand human expression…
Sometimes there are multiple ways to write code that works, but many of them are not be hospitable. As an example:
This is very concise, however, it is not readable. It is a monster of an expression!
What would happen if we just rewrite it like this?
It is more code, however, it is much more readable… (Don’t care about not understanding all the syntax now, we’ll see that later).
Python has a nice style guide available. It is good to consult it once in a while.
Professor Victor Norman, from Calvin, wrote a nice article calling attention to an important practice: we should always aim to write hospitable code.
You should read the whole article when you have time, but just to summarize some of the points:
There is a common perception that software written for scientific and engineering communities are the worst documented and organized ever. People usually think that since we are dealing with experts, it would be a waste of time to just make things clean and organized.